
// Definition for a binary tree node.
function TreeNode(val, left, right) {
    this.val = (val===undefined ? 0 : val)
    this.left = (left===undefined ? null : left)
    this.right = (right===undefined ? null : right)
}

/**
 * @param {TreeNode} root
 */
var BSTIterator = function(root) {
  let queue = [];
  function midView(node) {
    if(!node) return;
    midView(node.left);
    queue.push(node);
    midView(node.right);
  }
  midView(root);
  this.index = 0;
  this.nodeQueue = queue;
};

/**
 * @return {number}
 */
BSTIterator.prototype.next = function() {
  return this.nodeQueue[this.index++].val;
};

/**
 * @return {boolean}
 */
BSTIterator.prototype.hasNext = function() {
  return this.index < this.nodeQueue.length;
};

/**
 * Your BSTIterator object will be instantiated and called as such:
 * var obj = new BSTIterator(root)
 * var param_1 = obj.next()
 * var param_2 = obj.hasNext()
 */

let options = [["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"],
[[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []]];

